package Counter;

import Simulation.SimState;

public class ContinuousHistogram extends Histogram {
	/**
	 * Attribute: Simulation time of the last sample
	 */
	public long lastSampleTime;
	/**
	 * Attribute: Simulation time of the first sample
	 */
	public long firstSampleTime;
	/**
	 * Attribute: Number of samples
	 */
	public double lastSampleSize;

	public ContinuousHistogram(double ub, double lb, int numIntervals,
			String observedVariable) {
		super(ub, lb, numIntervals, observedVariable);
		setType(valueType.contineous);
		lastSampleTime = 0;
		firstSampleTime = 0;
		lastSampleSize = 0;
	}

	// Attention: count has to be called both at the beginning end at the end of
	// the simulation
	public void count(double x) {
		long tmp = SimState.instance.now - lastSampleTime;

		if (lastSampleSize < lowerBound) {
			incrementBin(0, tmp);
		}
		else if (lastSampleSize >= upperBound) {
			incrementBin(bins.size() - 1, tmp);
		}
		else {
		incrementBin(calcBin(lastSampleSize), tmp);
		}
		lastSampleTime = SimState.instance.now;
		lastSampleSize = x;

	}

}
